var timercount = 0;
var timestart = new Date();

function showtimer() {
	if (timercount) {
		clearTimeout(timercount);
		clockID = 0;
	}
	if (!timestart) {
		timestart = new Date();
	}
	var timeend = new Date();
	var timedifference = timeend.getTime() - timestart.getTime();
	timeend.setTime(timedifference);
	var minutes_passed = timeend.getMinutes();
	if (minutes_passed < 10) {
		minutes_passed = "0" + minutes_passed;
	}
	var seconds_passed = timeend.getSeconds();
	if (seconds_passed < 10) {
		seconds_passed = "0" + seconds_passed;
	}
	document.form.timetextarea.value = minutes_passed + ":" + seconds_passed;
	document.form.seconds.value = minutes_passed * 60 + seconds_passed;
	timercount = setTimeout("showtimer()", 1000);
}

function Start() {
	if (!timercount) {
		//timestart = new Date();
		//document.form.timetextarea.value = "00:00";

		timercount = setTimeout("showtimer()", 1000);
	} else {
		var timeend = new Date();
		var timedifference = timeend.getTime() - timestart.getTime();
		timeend.setTime(timedifference);
		var minutes_passed = timeend.getMinutes();
		if (minutes_passed < 10) {
			minutes_passed = "0" + minutes_passed;
		}
		var seconds_passed = timeend.getSeconds();
		if (seconds_passed < 10) {
			seconds_passed = "0" + seconds_passed;
		}
		var milliseconds_passed = timeend.getMilliseconds();
		if (milliseconds_passed < 10) {
			milliseconds_passed = "00" + milliseconds_passed;
		} else if (milliseconds_passed < 100) {
			milliseconds_passed = "0" + milliseconds_passed;
		}

	}

}

function Stop() {
	if (timercount) {
		clearTimeout(timercount);
		timercount = 0;
		var timeend = new Date();
		var timedifference = timeend.getTime() - timestart.getTime();
		timeend.setTime(timedifference);
		var minutes_passed = timeend.getMinutes();
		if (minutes_passed < 10) {
			minutes_passed = "0" + minutes_passed;
		}
		var seconds_passed = timeend.getSeconds();
		if (seconds_passed < 10) {
			seconds_passed = "0" + seconds_passed;
		}
		var milliseconds_passed = timeend.getMilliseconds();
		if (milliseconds_passed < 10) {
			milliseconds_passed = "00" + milliseconds_passed;
		} else if (milliseconds_passed < 100) {
			milliseconds_passed = "0" + milliseconds_passed;
		}
		document.form.timetextarea.value = minutes_passed + ":"
				+ seconds_passed;
		document.form.seconds.value =seconds_passed;
		document.form.minutesinseconds.value =minutes_passed*60;
	}
	timestart = null;

}

function Reset() {
	timestart = null;
	document.form.timetextarea.value = "00:00";

}
